<?php
/**
*
* ShopWindow Toolset
*
* Copyright (C) 2008 Digital Window Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*
*/

require_once(HOME_PATH.'classes'.DIRECTORY_SEPARATOR.'affiliatewindow'.DIRECTORY_SEPARATOR.'class.shopcore.php');
require_once(HOME_PATH.'classes'.DIRECTORY_SEPARATOR.'class.smarty.php');

// init ShopCore
if ( !is_object($oShopCore) ) {
	$oShopCore = new shopcore();
}

// init Smarty
if ( !is_object($oSmarty) ) {
	$oSmarty= new Smarty_agent();
}

// load env vars into params obj
$oShopCore->syncApiParams($oProductDisplayListParams);

if ( ADULT_CONTENT === false ) {
	$oProductDisplayListParams->bAdult = false;
}

# Get the products
$aProducts = $oShopCore->oApiProductList->getProductList($oProductDisplayListParams);



# Get additional API objects
$oMerchantParams = new stdClass();
$oCategoryParams = new stdClass();

if ( is_array($aProducts) ) {
	// Loop around products adding merchant and category id to our param objects //
	foreach ($aProducts as $oProduct) {
		$oMerchantParams->aMerchantIds[] = $oProduct->iMerchantId;
		$oCategoryParams->aCategoryIds[] = $oProduct->iCategoryId;
	}
}

// get merchants & categories
$aMerchants  = $oShopCore->oApiMerchant->getMerchant($oMerchantParams);
$aCategories = $oShopCore->oApiCategory->getCategory($oCategoryParams);


if ( is_array($aCategories) ) {
	// add links to objects
	foreach ( $aCategories as $oCategory ) {
		$oCategory->sLink = $oShopCore->buildLink(P_PRODUCTLIST, '', '', $oCategory->iId);
	}
}


if ( is_array($aProducts) ) {
	foreach( $aProducts as $oProduct ) {
		
		$oProduct->sLink 	= $oShopCore->buildLink(P_PRODUCT, $oProduct->iId);
		$oProduct->sBuyLink = $oShopCore->buildLink(P_GOTO, $oProduct->iId, $oProduct->iMerchantId);
	
		// assign objects
		$oProduct->oMerchant = $aMerchants[$oProduct->iMerchantId];
		$oProduct->oCategory = $aCategories[$oProduct->iCategoryId];
	}
}


$oShopCore->buildBreadCrumb();


# SMARTY ASSIGN
$oSmarty->assign('sBreadCrumbText', $oShopCore->getBreadCrumb(false));
$oSmarty->assign('sBreadCrumbHtml', $oShopCore->getBreadCrumb());
$oSmarty->assign('aProducts', $aProducts);

?>